Button-click events are delivered to the actionPerformed()
method,
but it always does the same thing,
regardless of which button is clicked.
Look again at the method:
public void actionPerformed( Action Event evt) { getContentPane().setBackground( Color.blue ); repaint(); }
The picture shows the present situation. Event objects from both buttons are delivered to the same method, which changes the background to blue no matter what event it receives.
We would like the ActionEvent
that is delivered to
actionPerformed()
setActionCommand(String command)
Now each button sends its command
(a String) as part of
the ActionEvent
when it is clicked.
The actionPerformed()
If you don't use setActionCommand()
What object(s) is setActionCommand()
part of?